package com.example.pptcontrol;


import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.app.Activity;
import android.util.Log;
import android.view.GestureDetector;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.TextView;

public class MainActivity extends Activity  implements Handler.Callback  {

	 // Gesture support
    private GestureDetector _gestureDetector = null;
    private GestureListener gestureListener = null;
    Handler mHandler ;
    TextView mCommentsTextView;
	@SuppressWarnings("deprecation")
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.activity_main);
		
		mHandler = new Handler(this);
		 // Gesture support
        gestureListener =  new GestureListener();
        gestureListener.mUILooperHandler=mHandler;
        _gestureDetector = new GestureDetector( gestureListener );
        
        
		mCommentsTextView = (TextView)findViewById(R.id.comments);
	}
	@Override
	public boolean handleMessage(Message msg) {
		Log.i(MainActivity.class.getName(), msg.obj.toString());
		mCommentsTextView.setText(msg.obj.toString());
		return true;
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

    public boolean dispatchTouchEvent(MotionEvent ev)
    {
    	boolean handled = super.dispatchTouchEvent(ev); 
    	if ( !handled )
    	{
    		Log.i(MainActivity.class.getName(), "dispatch touch event");
    		handled = _gestureDetector.onTouchEvent( ev );
    	}
    	
    	return handled; 
    }
}
